<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:s="http://www.w3.org/2001/XMLSchema"
             xmlns:s0="http://tempuri.org/" 
             xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
             xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
             xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">
    <xsl:variable name="service.endpoint" select="//*[local-name()='service']/*[local-name()='port']/*[local-name()='address']/@location"/>
    <xsl:variable name="service.namespace" select="//*[local-name()='schema']/@targetNamespace"/>

    <xsl:output method="text"/>
    
<xsl:template match="/">     
&lt;%
    
Function Page_Load()                  
    Dim action, result, resultxml, dom, tempObj
    Dim docReceived, RequestBody, RequestArgs, arguments
    Set docReceived   = CreateObject("Microsoft.XMLDOM") 
    Set arguments     = CreateObject("Scripting.Dictionary")
    docReceived.async = False 
    If docReceived.load (Request) Then
        Exit Function
    End If
    
    Set ProxyAddress = docReceived.selectSingleNode ("//@endpoint")
    If Not ProxyAddress Is Nothing Then 
        Response.Write OpenURL (ProxyAddress.text , docReceived.xml)
        Set docReceived = Nothing
        Response.End
    End If
    
    
    Set RequestBody  = docReceived.selectSingleNode ("//soap:Body/*")
    Set RequestArgs  = RequestBody.selectNodes ("./*")
    For Each f in RequestArgs
        arguments.Add f.nodename, f.text
    Next
    action = RequestBody.nodename
            
<xsl:apply-templates select="//*[local-name()='portType']"/> 
End Function             
          

<xsl:apply-templates select="//*[local-name()='schema']/*[local-name()='complexType']"/>
  

function OpenURL(frmUrl, strData)
    on error resume next
    dim oXMLHttp 
    Set oXMLHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")    
 
    with oXMLHttp
        .Open "POST", frmUrl, False 
        .send strData  
        if .Status = 200 then
            OpenURL = .responseText 
        else
            OpenURL = ""
        end if
    end with 
    If Err then
        OpenURL = Err.description &amp; vbcrlf &amp; frmUrl
    End If
    Set oXMLHttp = nothing
end function  
Page_Load
%&gt;
</xsl:template>


    <xsl:template match="//*[local-name()='element']">
    <xsl:for-each select="./*[local-name()='complexType']/*[local-name()='sequence']/*[local-name()='element']"
        >arguments("<xsl:value-of select="@name"/>")<xsl:if test="following-sibling::*[local-name()='element']">, </xsl:if>
    </xsl:for-each>
</xsl:template>


    <xsl:template match="//*[local-name()='operation']">
        <xsl:variable name="name" select="@name"/>
        <xsl:variable name="response" select="//*[local-name()='element'][@name=concat($name,'Response')]"/>
        <xsl:variable name="type" select="$response/*[local-name()='complexType']/*[local-name()='sequence']/*[local-name()='element']"/>
        <xsl:variable name="type.prefix" select="substring-before($type/@type,':')"/>
        <xsl:variable name="type.suffix">
             <xsl:if test="string-length($type.prefix) &gt; 0">.serialize()</xsl:if>
        </xsl:variable>
        <xsl:variable name="type.name">
            <xsl:choose>
                <xsl:when test="contains($type/@type,':')">
                    <xsl:value-of  select="substring-after($type/@type,':')"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$type/@type"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="type.max">
            <xsl:choose>
                <xsl:when test="$type/@maxOccurs='unbounded'">array()</xsl:when>
                <xsl:otherwise>""</xsl:otherwise>
            </xsl:choose>
        </xsl:variable> 
    <xsl:variable name="ref.key" select="//*[local-name()='schema']/*[local-name()='complexType'][@name=$type.name]"/>
<xsl:if test="not (preceding::*[local-name()='operation'][@name=$name])">
    If action = "<xsl:value-of select="@name"/>" Then     
        result    = "" ' initialize function return value here<xsl:choose><xsl:when test="$type/@maxOccurs='unbounded'">                                    
        results   = <xsl:value-of select="@name"/>(<xsl:apply-templates select="//*[local-name()='element'][@name=$name]"/>) ' call function                              
        For e = 0 to Ubound(results)                                                         
            Set tempObj = results (e)                                                            
            result = result &amp; "&lt;" &amp; action &amp; "Result&gt;" &amp; tempObj<xsl:value-of select="$type.suffix"/> 
            result = result &amp; "&lt;/" &amp; action &amp; "Result&gt;"                                                            
        Next </xsl:when><xsl:otherwise>
        result    = result &amp; "&lt;" &amp; action &amp; "Result&gt;" 
        <xsl:choose>
          <xsl:when test="$ref.key"> 
        Set o<xsl:value-of select="$type.name"/> = <xsl:value-of select="@name"/>(<xsl:apply-templates select="//*[local-name()='element'][@name=$name]"/>) 
        result    = result &amp; o<xsl:value-of select="$type.name"/>.serialize()        
          </xsl:when>
          <xsl:otherwise>
        result    = result &amp; <xsl:value-of select="@name"/>(<xsl:apply-templates select="//*[local-name()='element'][@name=$name]"/>) 
          </xsl:otherwise>
        </xsl:choose>  
        result    = result &amp; '&lt;/' &amp; action &amp; 'Result&gt;'</xsl:otherwise></xsl:choose>  
        resultxml = '&lt;' &amp; action &amp; 'Response xmlns="<xsl:value-of select="$service.namespace"/>"&gt;' &amp; result &amp; '&lt;/' &amp; action &amp; 'Response&gt;'                                      
    End If  
     
</xsl:if>
        
    </xsl:template>

  <xsl:template name="jazz.result">
    <xsl:param name="element"/>
    <xsl:param name="indent"/>
    <xsl:param name="count">0</xsl:param>
    <!-- get the @NAME of this element -->
    <xsl:variable name="name" select="$element/@name"/>
    <xsl:variable name="array" select="$element/@maxOccurs='unbounded'"/>
    <!-- get the @TYPE of this element -->
    <xsl:variable name="type" select="substring-after($element/@type,':')"/>
    <!-- look for any complexTypes with this name -->
    <xsl:variable name="ref.key" select="//*[local-name()='schema']/*[local-name()='complexType'][@name=$type]"/>
    <!-- look for any child elements for the complexType -->
    <xsl:variable name="ref.node" select="$ref.key/*[local-name()='sequence']/*[local-name()='element']"/><xsl:choose>
      <xsl:when test="$ref.key"><!-- for each child element, write its TYPE -->
       # <xsl:value-of select="$name"/>
        <xsl:call-template name="jazz.result.node">
        <xsl:with-param name="elements" select="$ref.node"/>
          <xsl:with-param name="indent" select="$indent"/>
          <xsl:with-param name="parent" select="$type"/>
      </xsl:call-template>
      </xsl:when>
      <xsl:otherwise><!-- when no children are left, write the TYPE -->
        $result.=$<xsl:value-of select="$type"/>;</xsl:otherwise>
    </xsl:choose>
  </xsl:template>
    
  
  <xsl:template name="jazz.result.node">
    <xsl:param name="elements"/>
    <xsl:param name="parent"/>
    <xsl:param name="indent"/>
    <xsl:variable name="element" select="$elements[1]"/>
    <xsl:variable name="next" select="$elements[position()!=1]"/>
    <xsl:variable name="type" select="substring-after($element/@type,':')"/>
    <xsl:variable name="array" select="$element/@maxOccurs='unbounded'"/>
    <xsl:variable name="ref.key" select="//*[local-name()='schema']/*[local-name()='complexType'][@name=$type]"/>
    <xsl:if test="$array">
      # output an ARRAY of these values
        $o<xsl:value-of select="$element/@name"/> = $o<xsl:value-of select="$parent"/>-&gt;<xsl:value-of select="$element/@name"/>;
    </xsl:if>
        $result.='&lt;<xsl:value-of select="$element/@name"/>&gt;';<xsl:call-template name="jazz.result"> 
  <xsl:with-param name="element" select="$element"/>
  <xsl:with-param name="indent" select="concat($indent,'  ')"/>
</xsl:call-template>
        $result.='&lt;/<xsl:value-of select="$element/@name"/>&gt;';<xsl:if test="$next"> 
      <xsl:call-template name="jazz.result.node">
        <xsl:with-param name="elements" select="$next"/>
        <xsl:with-param name="indent" select="$indent"/>
        <xsl:with-param name="parent" select="$parent"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  
<xsl:template name="form.invoke">
    <xsl:param name="method"/>
    <xsl:param name="for" select="//*[local-name()='element'][@name=$method]/*[local-name()='complexType']/*[local-name()='sequence']/*[local-name()='element']"/>
    <xsl:param name="me" select="$for[1]"/>
    <xsl:param name="next" select="$for[position()!=1]"/><xsl:if test="$me"> 
    request+="&lt;<xsl:value-of select="$me/@name"/>&gt;" + <xsl:value-of select="$me/@name"/> + "&lt;/<xsl:value-of select="$me/@name"/>&gt;";<xsl:if test="$next">
<xsl:call-template name="form.invoke">
<xsl:with-param name="for" select="$next"/>
</xsl:call-template>
    </xsl:if></xsl:if>
</xsl:template>

  <xsl:template match="//*[local-name()='portType']">

    <xsl:apply-templates select="./*[local-name()='operation']">
    </xsl:apply-templates>
  </xsl:template>


  <xsl:template match="//*[local-name()='schema']/*[local-name()='complexType']"> 
    <xsl:param name="type.name" select="@name"/>
Class <xsl:value-of select="@name"/><xsl:for-each select="./*/*[local-name()='element']">
    Dim <xsl:value-of select="@name"/></xsl:for-each> 
        
    Public Function serialize()
        Dim output 
        output=""<xsl:for-each select="./*/*[local-name()='element']"> 
      <xsl:choose>
        <xsl:when test="@maxOccurs='unbounded'">
        output = output &amp; "&lt;<xsl:value-of select="@name"/>&gt;"
        For i = 0 to Ubound (Me.<xsl:value-of select="@name"/>) 
        <xsl:choose>
          <xsl:when test="substring-before(@type,':')='s'">
            output = output &amp; "&lt;<xsl:value-of select="@name"/>&gt;&lt;![CDATA[" &amp; Me.<xsl:value-of select="@name"/> &amp; "]]&gt;&lt;/<xsl:value-of select="@name"/>&gt;"</xsl:when> 
          <xsl:otherwise>
            output = output &amp; Me.<xsl:value-of select="@name"/>[$i]-&gt;serialize ();</xsl:otherwise> 
        </xsl:choose>
        Next
        output = output &amp; "&lt;/<xsl:value-of select="@name"/>&gt;";</xsl:when>        
        <xsl:otherwise><xsl:choose>
          <xsl:when test="substring-before(@type,':')='s'">
        output = output &amp; "&lt;<xsl:value-of select="@name"/>&gt;&lt;![CDATA[" &amp; Me.<xsl:value-of select="@name"/> &amp; "]]&gt;&lt;/<xsl:value-of select="@name"/>&gt;"</xsl:when> 
          <xsl:otherwise>
        output = output &amp; Me.<xsl:value-of select="@name"/>-&gt;serialize ()</xsl:otherwise> 
        </xsl:choose></xsl:otherwise> 
          </xsl:choose></xsl:for-each> 
        serialize = output      
    End Function   
End Class
  </xsl:template>

 
</xsl:stylesheet> 
